<?php
/**
 * @name ss_GetThumbnailMTV
 * @abstract class to fetch MTV thumbnail image related to a search query passed as param
 * @param $searchString
 * 
 */
class ss_GetThumbnailMTV {

  function ss_GetThumbnailMTV ($searchString){
     
      
     if ($searchString !== ' ' ||  $searchString !== null) {
      
      $searchString = urlencode($searchString);  
      //var_dump($searchString);
      //die();  
     
     $url = 'http://api.mtvnservices.com/1/video/search/?term='.$searchString.'&start-index=1&max-results=1';
           
     $doc = new DOMDocument();
     $doc->load($url);
          
     $entries = $doc->getElementsByTagName( "entry" ); 
           
        foreach ( $entries as $entry ) { 
        
          $thumb = $entry->getElementsByTagName( "thumbnail" );
          
          $counter = 0;
          while ($thumb->item($counter) !== null) {
          	
            $thumbValue = $thumb->item($counter)->getAttributeNode("url")->value;
          	$counter = $counter+1;
            
            //var_dump($thumbValue);
          	
          	 //if ( strpos($thumbValue, '70x53')!==false) {
          	 if ( strpos($thumbValue, '140x105')!==false) {
          	    $out = '<div class="thumbmtv" alt="'.$searchString.'"><img border="0" src="'.$thumbValue.'" /></div>';
                return  $out;
              }
          	
          	
          	
          
          	
          	
          	
          }
          
        	 
        	     
            
        	
        }
                            
      }

   }
    
}